﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PMS.BusinessFacade;
using PMS.EntityManage;
using PMS.Common;
using PMS.EntityQuery;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using BusinessFacade;
using EntityManage;

public partial class Modules_Personal_PerfApplyView : System.Web.UI.Page
{
    IPerf_Personal_TargetTypeHandler ttHandler = new Perf_Personal_TargetTypeManage();
    IPerf_Personal_EvaluateHandler evaHandler = new Perf_Personal_EvaluateManage();
    IPerf_Personal_EvaluateHandlerExt evaExtHandler = new Perf_Personal_EvaluateManageExt();
    IPerf_Personal_EvaluateDtlHandler evaDtlHandler = new Perf_Personal_EvaluateDtlManage();
    IPerf_Personal_TargetHandler targetHandler = new Perf_Personal_TargetManage();
    ISys_UserHandler userHandler = new Sys_UserManage();
    ISys_OrganizationHandler orgHandler = new Sys_OrganizationManage();
    ISys_PostHandler postHandler = new Sys_PostManage();
    IPerf_Personal_TargetOwnerHandler toHandler = new Perf_Personal_TargetOwnerManage();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            dataBind();
        }
    }

    private void dataBind()
    {
        if (Request["ID"] != null && Request["ID"] != string.Empty)
        {
            int ID = 0;
            int.TryParse(Request["ID"], out ID);

            if (ID != 0)
            {
                try
                {
                    //Perf_Personal_FinalAssignQuery finalAssignQuery = finalAssignHandler.GetPerf_Personal_FinalAssignQuery(ID);
                    Perf_Personal_EvaluateQuery evalQuery = evaHandler.GetPerf_Personal_EvaluateQuery(ID);
                    if (evalQuery != null)
                    {
                        DataTable dt = evaDtlHandler.GetPerf_Personal_EvaluateDtlList(
                            " Evaluate_ID = @Evaluate_ID", new SqlParameter[] { new SqlParameter("@Evaluate_ID", evalQuery.ID)
                            });

                        gvTargetList.DataSource = dt;
                        gvTargetList.DataBind();

                        Sys_UserQuery userQuery = userHandler.GetSys_UserQuery(evalQuery.Target_User_ID);
                        if (userQuery != null)
                            lblTargetUser.Text = userQuery.Name;

                        Perf_Personal_TargetOwnerQuery toQuery = toHandler.GetPerf_Personal_TargetOwnerQuery(evalQuery.TargetOwner_ID);
                        if (toQuery != null)
                            lblTargetOwner.Text = toQuery.Name;

                        float totalScore = evaExtHandler.GetTotalScore(evalQuery.ID);
                        totalScore = totalScore + 100;
                        lblTotalScore.Text = totalScore.ToString();
                    }
                }
                catch
                {
                    Jscript.Alert("操作失败!", this.Page);
                }
            }
        }
    }

    protected void gvTargetList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.RowIndex > -1)
            {
                Perf_Personal_TargetQuery targetQuery = targetHandler.GetPerf_Personal_TargetQuery(int.Parse(e.Row.Cells[0].Text));
                if (targetQuery != null)
                {
                    e.Row.Cells[0].Text = targetQuery.Code;
                    e.Row.Cells[1].Text = targetQuery.Name;
                    Perf_Personal_TargetTypeQuery ttQuery = ttHandler.GetPerf_Personal_TargetTypeQuery(targetQuery.TargetType_ID);
                    if (ttQuery != null)
                    {
                        e.Row.Cells[2].Text = ttQuery.Name;
                    }
                    e.Row.Cells[3].Text = targetQuery.Score.ToString();
                }
                else
                {
                    e.Row.Cells[0].Text = "";
                    e.Row.Cells[1].Text = "";
                    e.Row.Cells[2].Text = "";
                    e.Row.Cells[3].Text = "";
                }
            }
        }
    }

}
